import axios from "axios"
import type { ReturnLoginInfo, SentLoginInfo } from "../models/Login"
import type { Result } from "../models/ResultModel"

export const loginAPI = async (loginInfo: SentLoginInfo): Promise<Result<ReturnLoginInfo>> => {
    console.log(`API登陆 ${loginInfo.email}...`)
    try {
        // 发送取消上传请求
        const response = await axios.post('/api/lg/login',
            loginInfo,
            { headers: { 'Content-Type': 'application/json' } }
        )
        console.log("后端返回的信息码：", response.data.code)              //调试
        return response.data
    } catch (error) {
        // 取消上传失败，捕获异常
        console.error('获取资源数据失败:', error)
        throw new Error('网络错误')
    }
}


export const autoLoginAPI = async (token: string): Promise<Result<ReturnLoginInfo>> => {
    console.log(`API自动登陆...`)
    try {
        // 发送取消上传请求
        const response = await axios.post('/api/lg/autoLogin',
            token,
            { headers: { 'Content-Type': 'application/json' } }
        )
        console.log("后端返回的信息码：", response.data.code)              //调试
        return response.data
    } catch (error) {
        // 取消上传失败，捕获异常
        console.error('获取资源数据失败:', error)
        throw new Error('网络错误')
    }
} 